﻿#region Header

// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

#region

using System.Collections;
using System.Collections.Generic;

#endregion

namespace Majesty_of_Omega.Util
{
    /// <summary>
    /// Helper class to compare 2 collections
    /// </summary>
    public static class EqualHelper
    {
        /// <summary>
        /// This function determines, if the given collections are equal. This function is important, because the build in 
        /// equal operators of the <see cref="List{T}" /> don't work as expected.
        /// </summary>
        /// <param name="collectionA">The collection A.</param>
        /// <param name="collectionB">The collection B.</param>
        /// <returns></returns>
        public static bool AreCollectionsEqual(IEnumerable collectionA, IEnumerable collectionB)
        {
            if (collectionA == null) return false;
            if (collectionB == null) return false;

            IEnumerator enumeratorA = collectionA.GetEnumerator();
            IEnumerator enumeratorB = collectionB.GetEnumerator();

            while (enumeratorA.MoveNext())
            {
                if (!enumeratorB.MoveNext()) return false;
                if (!enumeratorA.Current.Equals(enumeratorB.Current)) return false;
            }
            return true;
        }
    }
}